<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<isperp:userView readonly="true">
	<jsp:body>

<form:form commandName="model" cssClass="validate"
			action="app/user/save">
	<form:hidden path="id" />
    <form:hidden path="areCustomer" />
	<div class="header">
		<h2>&nbsp;&nbsp;基本信息</h2>
	</div>

	<table class=" form-table">
		<tbody>
			<tr>
				<c:if test="${not empty model.id }">
					<td class="td2" rowspan="5"
								style="text-align: center;width:155px !important;vertical-align: top;">


						<isperp:photoUploader imgName="photo" cutType="1" imgWidth="105"
									imgHeight="110" imgSrc="${model.photo}" id="photo"
									imgPath="users/${model.name }" imgFormat="png/gif/jpg"
									showDescription="false"></isperp:photoUploader>
							</td>
				</c:if>
				<td class="td1">账号：</td>
				<td class="td2"><c:choose>
						<c:when test="${empty model.name }">
							<form:input path="name" onchange="userNameChange()" />
							<form:hidden path="password" />
						</c:when>
						<c:otherwise>
							<form:hidden path="name" />
							<label style="font-weight: 700;padding:0 2px;color:#000000">${model.name}</label>
						</c:otherwise>
					</c:choose>
						</td>
				<td></td>
				<td></td>


			</tr>


			<tr>
				<td class="td1">姓名：</td>
				<td class="td2"><form:input path="fullname" cssClass="required" />
				</td>

				<td class="td1">生日：</td>
				<td class="td2">
				    
					
			<div style="display:none">
			<select id="idYear" style="display:none" name="idYear" data=""
									data-allow-empty="false" data-width="40px"></select>
							</div> <select id="idMonth" name="birthdayMonth" data=""
							data-width="80px" data-allow-empty="false"></select>月 <span
							id="qsDay" style=""><select id="idDay" data-width="80px"
								data-width="100px" name="birthdayDay" data=""
								data-allow-empty="false"></select>日</span>
			</td>
		</tr>
				
				
				</td>
			</tr>
					

			<tr>
				<td class="td1">性别：</td>
				<td class="td2"><form:radiobuttons path="gender" items="${sex}"
								itemLabel="name" itemValue="code" />
						</td>
				<td class="td1">是否有效：</td>
				<td class="td2"><form:checkbox path="enable" />
						</td>
			</tr>

			<tr>

				<td class="td1">所属客户：</td>
				<td class="td2" colspan="3">
				<form:input path="customerId" style="display:none" />
				<isperp:listSelector autocomplete="true" id="customerSelector"
								afterSelectEmpty="clearCustomer()" displayColumn="name"
								name="customerName" url="customer/customer/list"
								autocompleteDisplay="item.data[o.displayColumn]"
								autocompleteUrl="customer/customer/autocompleteList"
								valueColumn="id" valueControlId="customerId"
								displayValue="${model.customerName }"
								displayValueCssStyle="width:142px" displayValueCssClass="required">
								<isperp:column name="id" title="id" hidden="true"></isperp:column>
									<isperp:column name="code" title="编号" width="80">
									</isperp:column>
									<isperp:column name="name" title="客户名称" width="150">
									</isperp:column>
									<isperp:column name="area" title="地区" width="80">
									</isperp:column>
									<isperp:column name="linkman" title="联系人" width="80">
									</isperp:column>
									<isperp:column name="linktel" title="联系电话" width="80">
									</isperp:column>
									
				</isperp:listSelector>
						</td>
				
			</tr>
			<tr>
			   <td class="td1">部门：</td>
				<td class="td2" colspan="3"><form:input path="departmentName" />
						</td>
			
			</tr>
			<tr>

				<td class="td1">职务：</td>
				<td class="td2"><form:input path="position" />
						</td>


				<td class="td1">类型：</td>
				<td class="td2"><isperp:dictSelector id="type" name="type"
								hasEmptyValue="false" selectedValue="${model.type }"
								type="radio" typeCode="USER_TYPE"></isperp:dictSelector>
						</td>
			</tr>

			 

		</tbody>
	</table>

	<div class="header">
		<h2>&nbsp;&nbsp;联系方式</h2>
	</div>

	<table class=" form-table">
		<tbody>
		   <tr>
				<td class="td1">联系人：</td>
				<td class="td2" colspan="3"><form:input path="title"
								cssStyle="width:84%" />
						</td>
			</tr>
			<tr>


				<td class="td1">手机：</td>
				<td class="td2"><form:input path="mobile" cssClass=""
								cssStyle="width:80%" maxlength="100" />
				</td>
				<td class="td1">邮件：</td>
				<td class="td2"><form:input path="email" cssClass=" email"
								maxlength="100" cssStyle="width:80%" />
						</td>
			</tr>
			<tr>
				<td class="td1">电话：</td>
				<td class="td2"><form:input path="tel" maxlength="100"
								cssStyle="width:80%" />
				</td>

				<td class="td1">联系地址：</td>
				<td class="td2"><form:input path="address" maxlength="200"
								cssStyle="width:80%" />
				</td>
			</tr>
		</tbody>
	</table>

	<div class="header">
		<h2>&nbsp;&nbsp;其他信息</h2>
	</div>
	<table class=" form-table">
		<tbody>
			
			<tr>
				<td class="td1">技能：</td>
				<td class="td2" colspan="3"><form:textarea path="skills"
								maxlength="2000" cssStyle="width:84%" />
						</td>
			</tr>
			<tr>
				<td class="td1">备注：</td>
				<td class="td2" colspan="3"><form:textarea path="memo"
								maxlength="2000" cssStyle="width:84%" />
						</td>
			</tr>
		</tbody>
	</table>
	<c:if test="${showBtn eq '1' }">
	   <div class="header">
		<h2>&nbsp;&nbsp;设置角色（如果帐号为空，此设置将无效）</h2>
	</div>

	<table class=" form-table">
		<tr>
			<td class="td2" colspan="3" style="padding:8px 10px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<form:checkboxes
								path="selectedRoles"
								onchange="javascript:selectedRoles_onchange()"
								items="${viewRole}" itemLabel="name" itemValue="id" />
			</td>
		</tr>
	</table>
	</c:if>
	
</form:form>
</jsp:body>
</isperp:userView>

<isperp:buttonList>
	<button class="submit" onclick="isperp.submitForm();return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
<script type="text/javascript">
	$(function() {
		var bdayMonth = '${model.birthdayMonth}';
		var bdayDay = '${model.birthdayDay}';
		if (bdayMonth)
			$("#idMonth").val(bdayMonth);
		else
			$("#idMonth").val("");
		if (bdayDay)
			$("#idDay").val(bdayDay);
		else
			$("#idDay").val("");
	});

	var myDate = new Date();
	$("#dateSelector").DateSelector({
		ctlYearId : 'idYear',
		ctlMonthId : 'idMonth',
		defYear : 2000,
		defMonth : 1,
		defDay : 1,
		ctlDayId : 'idDay',
		minYear : 2000,
		maxYear : 2100
	});

	function clearCustomer() {
		$("#customerId").val("");
		$("#customerSelector").val("");
	}

	function afterSelectDept(ids, names, treeNode) {
		$.ajax({
			url : 'customer/customer/getCustomerByRelateDeptId?deptId=' + ids,
			success : function(data) {
				var cusName = data.name;
				var cusId = data.id;
				$("#customerId").val(cusId);
				$("#customerSelector").val(cusName);
			}
		});
	}

	function userNameChange() {

		var id = '${model.id}';
		var name = $("#name").val();
		$.ajax({
			async : false,
			url : "app/user/ifExistsUser?id=" + id + "&name=" + name,
			success : function(data) {
				if (data.success == false) {
					isperp.alert("该用户已存在！");
					$("#name").val("");
				}
			}
		});
	}
</script>

